package com.novel.app.view.shucheng;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.LayoutDirection;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dongdxiang.framework.BaseActivity;
import com.dongdxiang.framework.http.ImageLoader;
import com.dongdxiang.framework.http.QjResult;
import com.google.gson.reflect.TypeToken;
import com.novel.app.CommonUtils;
import com.novel.app.R;
import com.novel.app.utils.Configs;
import com.novel.app.view.shucheng.bean.ShuChengEntity;
import com.novel.app.view.storys.StoryActivity;
import com.novel.app.view.storys.StoryDetailActivity;
import com.novel.app.view.storys.bean.StoryDetailEntity;
import com.novel.app.view.storys.bean.StoryEntity;

import java.util.List;

/**
 * Created by d_xxiang on 2016/12/15.
 */
public class ShuChengActivity extends BaseActivity{
    private LinearLayout hot;
    private LinearLayout finished;
    private LinearLayout news;
    private ShuChengEntity shuChengEntity;

    @Override
    protected void onActivityCreate(Bundle savedInstanceState) {
        super.setContentView(R.layout.activity_shucheng);
        setCenterTitle("书城");
        setLeft_Btn("返回",R.mipmap.s6,onClickListener);
        hot = (LinearLayout)findViewById(R.id.hot);
        finished = (LinearLayout)findViewById(R.id.finished);
        news = (LinearLayout)findViewById(R.id.news);
        doNet();
    }

    private void doNet(){
        httpGetRequest(0, Configs.bookCity,new TypeToken<QjResult<ShuChengEntity>>() {},true,true);
    }

    public void btn_Click(View view){
        int cateId = 0;
        switch (view.getId()){
            case R.id.order:
                break;
            case R.id.man:
                cateId = 1;
                break;
            case R.id.gril:
                cateId = 2;
                break;
            case R.id.free:
                cateId = 3;
                break;
            case R.id.more_finished:
                cateId = 4;
                break;
            case R.id.more_news:
                cateId = 5;
                break;
        }
        Intent intent = new Intent(ShuChengActivity.this, StoryActivity.class);
        intent.putExtra("cateId",cateId);
        startActivity(intent);
    }




    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.btn_left:
                    finish();
                    break;
            }
        }
    };

    private CommonUtils.NovelClickListenter novelClickListenter = new CommonUtils.NovelClickListenter() {
        @Override
        public void goToNovel(String id) {
            Intent intent = new Intent(ShuChengActivity.this,StoryDetailActivity.class);
            intent.putExtra("id",id);
            startActivity(intent);
        }
    };

    @Override
    protected void onSucceed(int what, Object response) {
        if (response != null){
            shuChengEntity = (ShuChengEntity) response;
            List<StoryEntity.NovelEntity> list_recommend = shuChengEntity.getIs_recommend();
            List<StoryEntity.NovelEntity> list_finished = shuChengEntity.getIs_finished();
            List<StoryEntity.NovelEntity> list_new = shuChengEntity.getIs_new();
            CommonUtils.createView(baseActivity,hot,list_recommend,novelClickListenter);
            CommonUtils.createView(baseActivity,finished,list_finished,novelClickListenter);
            CommonUtils.createView(baseActivity,news,list_new,novelClickListenter);
        }
    }

    @Override
    protected void onFailed(int what, String url, Object tag, Exception exception, int responseCode, long networkMillis) {

    }
}
